<script type="text/javascript">
Ext.namespace('catalog.catalog.studentList');

catalog.catalog.studentList.SearchPanel = Ext.extend(catalog.ComplexEditorGrid, {
lastName:'Nume',
userName:'Nume utilizator',
firstName:'Prenume',
className:'Clasa',
address:'Adresa',
phone:'Telefon',
enabled:'Enabled',
bindRoles:'Bind Roles',
addUser:'Add User',
enableUsersButton:'Enable/Disable',
statusAccordConfMsg:'Please make sure users selected are all enabled or disabled!',
enableUsersConfMsg:'Are you sure want to enable the users?',
disableUsersConfMsg:'Are you sure want to disable the users?',

initComponent:function() {
//var sm = new Ext.grid.CheckboxSelectionModel();
var config = {
compSet:[{url:0,reader:0,columns:0,bbarAction:0}],
searchFields :[[
                this.lastName, {xtype:'textfield', name:'studentDTO.lastName', width:120}
                ]],
                urls: ['findStudent.action'],
                readers : [[
                {name: 'userName'},
                {name: 'lastName'},
                {name: 'firstName'},
                {name: 'className'},
                {name: 'address'},
                {name: 'phone'},
                ]],
columnsArray: [[
                {header: this.userName, width: 100, sortable: true, dataIndex: 'userName'},
                {header: this.lastName, width: 100, sortable: true, dataIndex: 'lastName',
                editor: new Ext.form.TextField({allowBlank: false})},
                {header: this.firstName, width: 180, sortable: true, dataIndex: 'firstName'},
                {header: this.className, width: 90, sortable: true, dataIndex: 'className',
                editor: new Ext.form.TextField({allowBlank: false})},
                {header: this.address, width: 70, sortable: true, dataIndex: 'address',
                editor: new Ext.form.TextField({allowBlank: false})},
                {header: this.phone, width: 70, sortable: true, dataIndex: 'phone',
                editor: new Ext.form.TextField({allowBlank: false})}
               // sm
                ]],

bbarActions:[[{
            text:mbLocale.deleteButton,
            iconCls :'delete-icon',
            scope:this,
            handler:this.deleteUsersFun
            },{
            text:mbLocale.submitButton,
            iconCls :'save-icon',
            scope:this,
            handler:this.saveUserFun
            }]],
  //          sm:sm
  autoScroll:true
}; // eo config object

Ext.apply(this, Ext.apply(this.initialConfig, config));
    catalog.catalog.studentList.SearchPanel.superclass.initComponent.apply(this, arguments);
    },

deleteUsersFun :function() {
                var studentDTOIds = this.selModel.selections.keys;
                if (studentDTOIds.length <= 0) {
                Ext.MessageBox.alert(mbLocale.infoMsg, mbLocale.gridMultRowSelectMsg);
                return;
                }
                var submitFun = function(buttonId, text, opt) {
                if (buttonId == 'yes') {
                catalog.util.ajaxRequest({
                url: 'deleteStudent.action',
                params:{'studentDTO.id':studentDTOIds},
                success:function(r,o){
                var res = Ext.decode(r.responseText);
                if (res && res.success){
                this.store.reload();
                }
                },
                failure:Ext.emptyFn
                },this);
                }
                };
                Ext.Msg.show({
                title:mbLocale.infoMsg,
                msg: mbLocale.delConfirmMsg,
                buttons: Ext.Msg.YESNO,
                scope: this,
                fn: submitFun,
                icon: Ext.MessageBox.QUESTION
                });
                },
saveUserFun :function() {
            var store = this.getStore();
            if(store.getModifiedRecords().length != 1){
            Ext.MessageBox.alert(mbLocale.infoMsg, mbLocale.gridRowEditMsg);
            return;
            }
            var studentDTO = store.getModifiedRecords()[0];
            var submitFun = function(buttonId, text, opt) {
            if (buttonId == 'yes') {
            catalog.util.ajaxRequest({
            url: 'updateStudent.action',
            params:{'studentDTO.id':studentDTO.id,
            'studentDTO.lastName':studentDTO.get('lastName'),
            'studentDTO.className':studentDTO.get('className')   ,
            'studentDTO.address':studentDTO.get('address') ,
            'studentDTO.phone':studentDTO.get('phone')}   ,
            success:function(r,o){
            var res=Ext.decode(r.responseText);
            if(res.message==false){
              Ext.Msg.show({
                            title:mbLocale.infoMsg,
                            msg: 'Modificarea clasei nu s-a putut poate realiza. Clasa introdusa nu exista. ',
                            buttons: Ext.Msg.OK,
                            scope: this
                        });
             }
            else{
               Ext.Msg.show({
                              title:mbLocale.infoMsg,
                              msg: 'Modificare realizata cu succes ',
                              buttons: Ext.Msg.OK,
                              scope: this
                          });
            }
            this.store.commitChanges();
             this.store.reload();
            },
            failure:function(r, o){

               // Ext.emptyFn
            }
            },this);
            }
            };
            Ext.Msg.show({
            title:mbLocale.infoMsg,
            msg: mbLocale.updateConfirmMsg,
            buttons: Ext.Msg.YESNO,
            scope: this,
            fn: submitFun,
            icon: Ext.MessageBox.QUESTION
            });
            }
});


try {studentListLocale();} catch (e) {}

Ext.onReady(function() {
            Ext.QuickTips.init();
            var formPanel = new catalog.catalog.studentList.SearchPanel();
                formPanel.store.reload();
            if (mainPanel) {
            mainPanel.getActiveTab().add(formPanel);
            mainPanel.getActiveTab().doLayout();
            } else {
            var vp = new Ext.Viewport({
            layout:'fit',
            items:[formPanel]
            });
            }
            });
</script>